import { Component, forwardRef, Input } from '@angular/core';
import { ControlValueAccessor, NG_VALUE_ACCESSOR } from '@angular/forms';
import { _HttpClient } from '@delon/theme';

@Component({
    selector: 'f-input',
    templateUrl: './f-input.component.html',
    providers: [{
        provide: NG_VALUE_ACCESSOR,
        useExisting: forwardRef(() => FInputComponent),
        multi: true
    }]
})
export class FInputComponent implements ControlValueAccessor {

    @Input("id")
    id = "";
    @Input("label")
    label = "";
    @Input("name")
    name = "";
    @Input("type")
    type = "";
    @Input("required")
    required = false;
    @Input("value")
    _value: any = null;

    set value(value: any){
        this._value = value;
        this.propagateChange(this._value);
    }

    get value(): any{
        return this._value;
    }

    propagateChange = (_: any) => { };

    writeValue(obj: any): void {
        this.value = obj;
    }
    registerOnChange(fn: any): void {
        this.propagateChange = fn;
    }
    registerOnTouched(fn: any): void {
        
    }

}